package pe.edu.upc.dew.sisrest.dao.hibernate;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.edu.upc.dew.sisrest.dao.PlatoDao;
import pe.edu.upc.dew.sisrest.model.Plato;

@Repository
public class PlatoDaoHibernate extends HibernateDaoSupport implements PlatoDao {

    @Autowired
    public PlatoDaoHibernate(SessionFactory sessionFactory) {
        setSessionFactory(sessionFactory);
    }

    @Override
    public List<Plato> obtenerListaPlatos() {
        List list = getHibernateTemplate().find(" from Plato ");
        return list;
    }

    @Override
    public Plato obtenerPlatoById(String idPlato) {
        Plato plato = getHibernateTemplate().get(Plato.class, idPlato);
        return plato;
    }

    @Override
    public void guardarPlato(Plato plato) {
        getHibernateTemplate().saveOrUpdate(plato);
    }

    @Override
    public void actualizarPlato(Plato plato) {
        guardarPlato(plato);
    }

    @Override
    public void eliminarPlato(String idPlato) {
        Plato plato = obtenerPlatoById(idPlato);
        getHibernateTemplate().delete(plato);
    }
}